//
//  RXXHomeViewController.m
//  RXXKVideo
//
//  Created by 星仔 on 2019/3/17.
//  Copyright © 2019年 rxx. All rights reserved.
//

#import "RXXKHomeViewController.h"
#import "RXXKScrollView.h"
#import "const.h"
#import "RXXKMainViewController.h"
#import "RXXKSearchViewController.h"

@interface RXXKHomeViewController ()<UIScrollViewDelegate>

@property (nonatomic, strong) RXXKScrollView      *mainScrollView;
@property (nonatomic, strong) NSArray             *childs;
@property (nonatomic, strong) RXXKMainViewController      *mainVC;
@property (nonatomic, strong) RXXKSearchViewController    *searchVC;

@end

@implementation RXXKHomeViewController

#pragma mark - ♻️life cycle
- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    [self setupUI];
}
- (void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.navigationController.navigationBar.hidden = YES;
}
- (void)viewWillDisappear:(BOOL)animated{
    [super viewWillDisappear:animated];
    self.navigationController.navigationBar.hidden = NO;
}
#pragma mark - 🔒private
- (void)setupUI{
    [self.view addSubview:self.mainScrollView];
    [self.mainScrollView setFrame:CGRectMake(0, 0,RX_SCREEN_WIDTH, RX_SCREEN_HEIGHT)];
    self.childs = @[self.searchVC,self.mainVC];
    [self.childs enumerateObjectsUsingBlock:^(UIViewController * vc, NSUInteger idx, BOOL * _Nonnull stop) {
        [self addChildViewController:vc];
        [self.mainScrollView addSubview:vc.view];
        vc.view.frame = CGRectMake(idx *RX_SCREEN_WIDTH, 0, RX_SCREEN_WIDTH, RX_SCREEN_HEIGHT);
    }];
    self.mainScrollView.contentSize = CGSizeMake(self.childs.count *RX_SCREEN_WIDTH, RX_SCREEN_HEIGHT);
    self.mainScrollView.contentOffset = CGPointMake(RX_SCREEN_WIDTH, 0);
    
}
#pragma mark - 🚪public
#pragma mark - 🍐delegate
- (void)scrollViewDidScroll:(UIScrollView *)scrollView{
    NSLog(@"%s----%@",__func__,scrollView);
}
#pragma mark - 🔄overwrite
#pragma mark - ☎️notification
#pragma mark - 🎬event response
#pragma mark - ☸getter and setter
- (RXXKScrollView *)mainScrollView{
    if (!_mainScrollView) {
        _mainScrollView = [RXXKScrollView new];
        _mainScrollView.showsVerticalScrollIndicator = NO;
        _mainScrollView.showsHorizontalScrollIndicator = NO;
        _mainScrollView.pagingEnabled = YES;
        _mainScrollView.bounces = NO;
        _mainScrollView.backgroundColor = [UIColor redColor];
        _mainScrollView.delegate = self;
        if (@available(iOS 11.0, *)) {
            _mainScrollView.contentInsetAdjustmentBehavior = UIScrollViewContentInsetAdjustmentNever;
        }else{
            
        }
    }
    return _mainScrollView;
}
- (RXXKMainViewController *)mainVC{
    if (!_mainVC) {
        _mainVC = [RXXKMainViewController new];
    }
    return _mainVC;
}
- (RXXKSearchViewController *)searchVC{
    if (!_searchVC) {
        _searchVC = [RXXKSearchViewController new];
    }
    return _searchVC;
}
@end
